<?php

use Facebook\WebDriver\WebDriver;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverElement;
use Facebook\WebDriver\WebDriverExpectedCondition;

/**
 * Wait element and return it, or throw an exception
 *
 * @param WebDriver   $driver
 * @param WebDriverBy $locator
 * @param int         $timeout  timeout in second
 * @param int         $interval interval in millisecond
 *
 * @return WebDriverElement
 * @throws \Facebook\WebDriver\Exception\NoSuchElementException
 * @throws \Facebook\WebDriver\Exception\TimeOutException
 */
function getElement(WebDriver $driver, WebDriverBy $locator, $timeout = 10, $interval = 500): WebDriverElement
{
    return $driver->wait($timeout, $interval)
        ->until(WebDriverExpectedCondition::presenceOfElementLocated($locator), 'element not found');
}

/**
 * Changes all keys in an array to capital case
 *
 * @param array $input
 *
 * @return array an array with its keys capital-cased
 */
function array_change_key_capital_case(array $input)
{
    $newArr = [];
    foreach ($input as $k => $v) {
        $newArr[ucfirst($k)] = $v;
    }
    return $newArr;
}
